<template>
<div>
   <el-breadcrumb separator-class="el-icon-arrow-right">
  <el-breadcrumb-item :to="{ path: '/TeacherMain' }">首页</el-breadcrumb-item>
  <el-breadcrumb-item>教师信息管理</el-breadcrumb-item>
  <el-breadcrumb-item>教师信息添加</el-breadcrumb-item>
</el-breadcrumb>
  <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
    <el-form-item label="工号" >
    <el-input v-model="ruleForm.id"></el-input>
    </el-form-item>
  <el-form-item label="教师姓名" prop="name">
    <el-input v-model="ruleForm.teachername"></el-input>
  </el-form-item>
  <el-form-item label="教师年龄" prop="name">
    <el-input v-model="ruleForm.teacherage"></el-input>
  </el-form-item>
  <el-form-item label="教授班级" prop="name">
    <el-input v-model="ruleForm.teacherclass"></el-input>
  </el-form-item>
  <el-form-item label="班级成绩" prop="name">
    <el-input v-model="ruleForm.teacherscore"></el-input>
  </el-form-item>
  <el-form-item label="教师住址" prop="name">
    <el-input v-model="ruleForm.teacheraddress"></el-input>
  </el-form-item>
  <el-form-item>
    <el-button type="primary" @click="submitForm('ruleForm')">提交</el-button>
    <el-button @click="resetForm('ruleForm')">重置</el-button>
    <el-button type="info" @click="back">返回</el-button>
  </el-form-item>
</el-form>
</template>

<script>
import axios from 'axios'
export default {
  data () {
    return {
      ruleForm: {
        id: '',
        teachername: '',
        teacherage: '',
        teacherclass: '',
        teacherscore: '',
        teacheraddress: ''
      },
      rules: {
        name: [
          { required: true, message: '请输入', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    submitForm (formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          axios.post('http://localhost:8082/StudentManagement-Web/teacher/save.json', this.ruleForm).then(function (resp) { alert('success') })
        } else {
          console.log('失败!!')
          return false
        }
      })
    },
    resetForm (formName) {
      this.$refs[formName].resetFields()
    },
    back () {
      this.$router.replace('/TeacherMain')
    }
  }
}
</script>
